public class MyCircleQueue {

    int[] elem;
    int first = 0;
    int rear = 0;

    public MyCircleQueue(int k) {
        elem = new int[k + 1];
    }

    public boolean enQueue(int value) {
        if (isFull()) {
            return false;
        }

        elem[rear] = value;
        rear = (rear + 1) % elem.length;


        return true;

    }

    public boolean deQueue() {
        if (isEmpty()) {
            return false;
        }
        first = (first + 1) % elem.length;
        return true;

    }

    public int Front() {
        if (isEmpty()) {
            return -1;
        }
        return elem[first];

    }

    public int Rear() {
        if (isEmpty()) {
            return -1;
        }
        int p = (rear == 0 ? elem.length - 1 : rear - 1);
        return elem[p];

    }

    public boolean isEmpty() {
        return first == rear;

    }

    public boolean isFull() {
        if ((rear + 1) % elem.length == first) {
            return true;
        } else {
            return false;
        }

    }
}
